package com.nil.codegen.controller;

import com.nil.codegen.base.BaseController;
import com.nil.codegen.bean.ResponseResult;
import com.nil.codegen.domain.dto.DbDriverDTO;
import com.nil.codegen.domain.dto.DbDriverQueryDTO;
import com.nil.codegen.domain.entity.FileModel;
import com.nil.codegen.enums.DriverTypeEnum;
import com.nil.codegen.service.IDbDriverService;
import com.nil.codegen.service.IFileManageService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@RestController
@RequestMapping("/driver")
public class DbDriverController extends BaseController {

    @Resource
    private IFileManageService fileManageService;

    @Resource
    private IDbDriverService dbDriverService;


    @PostMapping("/lib-upload")
    public ResponseResult upload(@RequestParam("file") MultipartFile file) {
        FileModel fileModel = fileManageService.uploadFile(file);
        return success(fileModel);
    }


    @PostMapping("/save")
    public ResponseResult save(@RequestBody DbDriverDTO  driverDTO) {
        dbDriverService.saveDbDriver(driverDTO);
        return success("驱动保存成功!");
    }

    @GetMapping("/getAllDriverType")
    public ResponseResult getAllDriverType() {
        return success(DriverTypeEnum.toList());
    }

    @PostMapping("/pageList")
    public ResponseResult page(@RequestBody DbDriverQueryDTO queryDTO) {
        return success(dbDriverService.pageList(queryDTO));
    }


    @GetMapping("/listAll")
    public ResponseResult listAll() {
        return success(dbDriverService.listAll());
    }



}

